package lz.controls.managers
{
	import com.global.GlobalDef;
	import com.greensock.TweenLite;
	import com.greensock.easing.Quad;
	
	import flash.display.DisplayObject;
	import flash.geom.Point;

	/**
	 * 动画管理器
	 * @author lake
	 */	
	public class AnimationManager
	{
		/**
		 *动画显示列表
		 * item {func:func,data:data} 
		 */		
		private static var showList :Array = [];
		
		public function AnimationManager()
		{
		}
		/**
		 * 获取未显示完的动画个数 
		 * @return 
		 */		
		public static function getLength():int
		{
			return showList.length;
		}
		/**
		 * 添加动画 
		 * @param item
		 * 
		 */		
		public static function addItem(item :*):void
		{
			if(showList.length > 0)
			{
				showList.push(item);
			}
			else
			{
				showList.push(item);
				excuteItem(item);
			}
		}
		/**
		 *在列表头添加条目 
		 * @param item
		 * 
		 */		
		public static function unshiftItem(item :*):void
		{
			if(showList.length > 0)
			{
				showList.unshift(item);
			}
			else
			{
				showList.unshift(item);
				excuteItem(item);
			}
		}
		/**
		 *删除动画 
		 * 
		 */		
		public static function remove():void
		{
			showList.shift();
			if(showList.length > 0)
			{
				var item :* = showList[0];
				excuteItem(item);
			}
		}
		/**
		 *执行 
		 * @param item
		 * 
		 */		
		private static function excuteItem(item :*):void
		{
			var func :Function = item.func;
			var data :* = item.data;
			if(data)
			{
				func.call(null,data);
			}
			else
			{
				func.call();
			}
		}
		/**
		 * 飞向某处
		 * @param startPoint 开始位置
		 * @param disp 物品对象
		 * @param endPoint 目标位置
		 * @param vars 缓动参数
		 * @param duration 缓动时间
		 */		
		public static function moveToThing(startPoint :Point,
										 disp:DisplayObject,
										 endPoint:Point,
										 vars:Object,
										 duration:Number = 1):void
		{
			if(startPoint == null || disp == null)
			{
				return;
			}
			if(vars == null)
			{
				vars = {};
			}
			GlobalDef.GameStage.addChild(disp);
			disp.x = startPoint.x;
			disp.y = startPoint.y;
			vars.x = endPoint.x;
			vars.y = endPoint.y;
			vars.onComplete = flyComplete;
			vars.onCompleteParams = [disp];
			TweenLite.to(disp,duration,vars);
		}
		/**
		 *运动完毕 
		 * @param disp
		 * 
		 */		
		private static function flyComplete(disp :DisplayObject):void
		{
			if(disp && disp.parent)
			{
				disp.parent.removeChild(disp);
			}
		}
		/**
		 * 浅入 
		 * @param disp
		 * @param vars
		 * @param duration
		 */		
		public static function facadeIn(disp:DisplayObject,
										 vars:Object,
										 duration:Number = 1):void
		{
			if(disp == null)
			{
				return;
			}
			if(vars == null)
			{
				vars = {};
			}
			disp.alpha = 0;
			vars.alpha = 1;
			vars.onCompleteParams = [disp];
			TweenLite.to(disp,duration,vars);
		}
		/**
		 * 淡出 
		 * @param disp
		 * @param vars
		 * @param duration
		 */		
		public static function facadeOut(disp:DisplayObject,
										 vars:Object,
										 duration:Number = 1):void
		{
			if(disp == null)
			{
				return;
			}
			vars.alpha = 0;
			vars.onCompleteParams = [disp];
			vars.onComplete = flyComplete
			TweenLite.to(disp,duration,vars);
		}
	}
}